package com.project.service.impl;

import com.project.bean.ShoppingCarBean;
import com.project.mapper.IShopMapper;
import com.project.service.IShoppingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ShoppingCarServiceImpl implements IShoppingCarService {
    @Autowired
    private IShopMapper mapper;
    @Override
    public List<ShoppingCarBean> findByUser(int userId) {
        return mapper.findByUser(userId);
    }

    @Override
    public void add(int userId, int productId) {
        int c = mapper.hasUserShop(userId,productId);
        if(c == 0){
            mapper.addShop(userId,productId,1);
        }
        else{
            mapper.addDeShop(userId,productId,1);
        }

    }

    @Override
    public void update(int id, int number) {
        mapper.updateNum(id,number);
    }

    @Override
    public void del(int id) {
        mapper.del(id);
    }
}
